const BaseResult = require('./BaseResult');

class ResponseHandler {
    constructor(code, message, data){
        this.code = code;
        this.message = message;
        this.data = data || {};
        this.timestamp = Date.now();
    }

    static success(data){
        return new ResponseHandler(BaseResult.SUCCESS.code, BaseResult.SUCCESS.message, data);
    }

    static error(err){
        return new ResponseHandler(BaseResult.FAILED.code, BaseResult.FAILED.message, err);
    }

    static unauthorized(){
        return new ResponseHandler(BaseResult.UNAUTHORIZED.code, BaseResult.UNAUTHORIZED.message, null);
    }
}

module.exports = ResponseHandler;